package com.yxt.common.xml;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class SAXHandler extends DefaultHandler {
	private List<Map<String,String>> list = new ArrayList<Map<String,String>>();

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {

	}

	@Override
	public void endDocument() throws SAXException {
		super.endDocument();
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		super.endElement(uri, localName, qName);
	}

	@Override
	public void startDocument() throws SAXException {

		super.startDocument();
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		Map<String,String> data = new HashMap<String,String>();
		System.out.print(localName + " : " );
		for (int i = 0; i < attributes.getLength(); i++) {
			data.put(attributes.getLocalName(i), attributes.getValue(i));
			System.out.print("\t" + attributes.getLocalName(i)+" = " + attributes.getValue(i));
		}
		System.out.println();
		list.add(data);
	}
	
	public List<Map<String,String>> getXmlContent(){
		return list;
	}
}